package com.longxi.tianjintianbao.ui.adapter.multitype;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.SelectGoodsTrafficListListListener;
import com.longxi.tianjintianbao.model.GoodsTraffic;
import com.longxi.tianjintianbao.utils.MyUtils;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class GoodsTrafficListViewBinder extends ItemViewBinder<GoodsTraffic, GoodsTrafficListViewBinder.ViewHolder> {

    SelectGoodsTrafficListListListener listener;

    public GoodsTrafficListViewBinder(SelectGoodsTrafficListListListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_goods_traffic_list, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull GoodsTraffic goodsTraffic) {
        holder.mTvDate.setText(goodsTraffic.getMaketime());
        holder.mTvName.setText("申请人:" + goodsTraffic.getApplicant());
        holder.mTvAddress.setText("携出时间:"+ goodsTraffic.getReleasetime());
        holder.mTvTaskContent.setText("申请房间:" + MyUtils.accordDiagonalSwitchString(goodsTraffic.getHouse()) +
                                        "\n携出物品:" + goodsTraffic.getReleasegoods());

        holder.mLlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                listener.onSuccess(goodsTraffic);
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mLlBtn;
        TextView mTvDate;
        TextView mTvStatus;
        TextView mTvName;
        TextView mTvAddress;
        TextView mTvTaskContent;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvDate = itemView.findViewById(R.id.tvDate);
            mTvStatus = itemView.findViewById(R.id.tvStatus);
            mTvName = itemView.findViewById(R.id.tvName);
            mTvAddress = itemView.findViewById(R.id.tvAddress);
            mTvTaskContent = itemView.findViewById(R.id.tvTaskContent);
        }
    }
}
